package newcoder.lx_合并表记录;

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

/**
 * @Author Mr.wang
 * @Description 数据表记录包含表索引和数值（int范围的整数），请对表索引相同的记录进行合并，即将相同索引的数值进行求和运算，输出按照key值升序进行输出。
 * @Date 2020-04-11
 */
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()) {
            int nextInt = scanner.nextInt();
            Map<Integer, Integer> map = new HashMap<>(nextInt);
            for (int i = 0; i < nextInt; i++) {
                int key = scanner.nextInt();
                int value = scanner.nextInt();
                if (map.containsKey(key)) {
                    map.put(key, value + map.get(key));
                } else {
                    map.put(key, value);
                }
            }
            for (Map.Entry<Integer, Integer> entry : map.entrySet()) {
                System.out.println(entry.getKey() + " " + entry.getValue());
            }
        }
    }
}
